package c.e.a.b.g;

import java.util.concurrent.ExecutionException;
import javax.annotation.concurrent.GuardedBy;

public final class k implements b, c, d {
    public final Object a = new Object();
    public final int b;
    public final a0<Void> c;
    @GuardedBy("mLock")
    public int d;
    @GuardedBy("mLock")
    public int e;
    @GuardedBy("mLock")
    public int f;
    @GuardedBy("mLock")
    public Exception g;
    @GuardedBy("mLock")
    public boolean h;

    public k(int i, a0<Void> a0Var) {
        this.b = i;
        this.c = a0Var;
    }

    @GuardedBy("mLock")
    public final void a() {
        if ((this.d + this.e) + this.f == this.b) {
            if (this.g != null) {
                a0 a0Var = this.c;
                int i = this.e;
                int i2 = this.b;
                StringBuilder stringBuilder = new StringBuilder(54);
                stringBuilder.append(i);
                stringBuilder.append(" out of ");
                stringBuilder.append(i2);
                stringBuilder.append(" underlying tasks failed");
                a0Var.m(new ExecutionException(stringBuilder.toString(), this.g));
            } else if (this.h) {
                this.c.o();
            } else {
                this.c.n(null);
            }
        }
    }

    public final void b() {
        synchronized (this.a) {
            this.f++;
            this.h = true;
            a();
        }
    }

    public final void onFailure(Exception exception) {
        synchronized (this.a) {
            this.e++;
            this.g = exception;
            a();
        }
    }

    public final void onSuccess(Object obj) {
        synchronized (this.a) {
            this.d++;
            a();
        }
    }
}
